import logging

from dbtool import MysqlPool


def get_logger():
    # create logger
    logger_name = "global"
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)

    # create stream handler
    handler = logging.StreamHandler()
    handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    # create file handler
    log_path = "./logger.log"
    fh = logging.FileHandler(log_path, encoding='utf-8', mode='w')
    fh.setLevel(logging.DEBUG)
    # fmt = "%(asctime)-15s %(levelname)s %(filename)s %(lineno)d %(process)d %(message)s"
    # fmt = "%(asctime)-15s %(levelname)s %(filename)s %(lineno)d %(message)s"
    fmt = "%(message)s"
    datefmt = "%a %d %b %Y %H:%M:%S"
    formatter = logging.Formatter(fmt, datefmt)
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    return logger


# print log info
logger = get_logger()
logger.info('start logging')


class DBConfig:
    db_host = '116.62.163.101'
    db_port = 3306
    user = 'claim'
    password = 'Pw123456!'
    db_claim_dev = 'claim_dev'
    db_claim_test = 'claim_test'


db_claim_dev = MysqlPool(DBConfig.db_host, DBConfig.db_port, DBConfig.user, DBConfig.password, DBConfig.db_claim_dev)
db_claim_test = MysqlPool(DBConfig.db_host, DBConfig.db_port, DBConfig.user, DBConfig.password, DBConfig.db_claim_test)


ment2ent_url = 'http://shuyantech.com/api/cndbpedia/ment2ent?q={}&apikey={}'
avpair_url = 'http://shuyantech.com/api/cndbpedia/avpair?q={}&apikey={}'
api_key = 'ljqljqljq'

NAMES = ['别称', '别名', '又名', '又称', '也叫', '也称', '昵称', '俗名',
         '名称', '标准名称', '本名', '学名', '全称',
         '简称', '缩写', '缩略词', '简写',
         '英文名', '英文名称']